package com.weibo.user.service.imp;

import java.util.List;

import org.apache.log4j.Logger;

import com.weibo.sql.SqlFile;
import com.weibo.user.Billing;
import com.weibo.user.User;
import com.weibo.user.dao.UserDao;
import com.weibo.user.dao.imp.UserDaoImp;
import com.weibo.user.service.UserService;


public class UserServiceImp implements UserService {
	private static Logger logger =  Logger.getLogger(UserServiceImp.class);
	private UserDao userDao = new UserDaoImp();

	@Override
	public boolean deleteUser_byID(String user_id) {
		// TODO Auto-generated method stub
		return userDao.deleteUser_byID(user_id);
	}

	@Override
	public boolean deleteUser_byName(String user_name) {
		// TODO Auto-generated method stub
		return userDao.deleteUser_byName(user_name);
	}

	@Override
	public int getTotalSize() {
		// TODO Auto-generated method stub
		return userDao.getTotalSize(SqlFile.USER_LIST_TOTALSIZE);
	}

	@Override
	public User getUserByID(String id) {
		// TODO Auto-generated method stub
		return userDao.getUserByID(id);
	}

	@Override
	public User getUserByName(String name) {
		// TODO Auto-generated method stub
		return userDao.getUserByName(name);
	}

	@Override
	public List getUserList(int currentPage) {
		// TODO Auto-generated method stub
		return userDao.getUserList(currentPage);
	}

	@Override
	public List getUserList_BySql(String sql) {
		// TODO Auto-generated method stub
		return userDao.getUserList_BySql(sql);
	}

	@Override
	public boolean saveUser(User user) {
		// TODO Auto-generated method stub
		return userDao.saveUser(user);
	}

	@Override
	public boolean updateUser(User user) {
		// TODO Auto-generated method stub
		return userDao.updateUser(user);
	}

	@Override
	public boolean addUserYue(String userName, String yue) {
		User user=userDao.getUserByName(userName);
		try{
			int iyue=Integer.parseInt(yue);
			String suseryue=user.getUser_yue().equals("")?"0":user.getUser_yue();
			int useryue=Integer.parseInt(suseryue);
			int user_yue=iyue+useryue;
			user.setUser_yue(user_yue+"");
//			String userid=user.getUser_id();
			if(userDao.updateUser(user)&&userDao.addChargeBilling(userName,iyue)){
				return true;
			}else{
				return false;
			}
		}catch (Exception e) {
			return false;
		}
	}

	@Override
	public List getBillingList(int currentPage) {
		return userDao.getBillingList(currentPage);
	}

	@Override
	public List getChargeRecordList(int currentPage) {
		return userDao.getChargeRecordList(currentPage);
	}
	
}
